1 /**
2  * Context related interfaces.
3  * 
4  * Authors:
5  * 		Richard Andrew Cattermole
6  * 
7  * License:
8  * 		The MIT License (MIT)
9  *
10  *		Copyright (c) 2014 Devisualization (Richard Andrew Cattermole)
11  *  	
12  *		Permission is hereby granted, free of charge, to any person obtaining a copy
13  * 		of this software and associated documentation files (the "Software"), to deal
14  * 		in the Software without restriction, including without limitation the rights
15  * 		to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  * 		copies of the Software, and to permit persons to whom the Software is
17  * 		furnished to do so, subject to the following conditions:
18  *  	
19  * 		The above copyright notice and this permission notice shall be included in all
20  * 		copies or substantial portions of the Software.
21  *  	
22  * 		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * 		IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * 		FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * 		AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * 		LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * 		OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * 		SOFTWARE.
29  */
30 module devisualization.window.interfaces.context;
31 import devisualization.image.image;
32 
33 /**
34  * The type of context available.
35  */
36 enum WindowContextType : ushort {
37 	/**
38 	 * No context to be used.
39 	 */
40     None = 0,
41 
42 	/**
43 	 * Both legacy (1.x .. 2.x) and 3+ contexts for OpenGL.
44 	 * 3+ preferred if only one available.
45 	 */
46     Opengl = OpenglLegacy | Opengl3Plus,
47 
48 	/**
49 	 * Direct3D context.
50 	 * Highly unlikely implemented.
51 	 */
52     Direct3D = 1 << 1,
53     
54 	/**
55 	 * Legacy OpenGL context (1.x .. 2.x)
56 	 */
57     OpenglLegacy = 1 << 2,
58 
59 	/**
60 	 * OpenGL context 3+
61 	 */
62     Opengl3Plus = 1 << 3,
63 
64 	/**
65 	 * A 2d buffer is provided to draw into
66 	 */
67 	Buffer2D = 1 << 4
68 }
69 
70 /**
71  * Context definition for a 3d rendering toolkit.
72  */
73 interface IContext {
74     @property {
75         /**
76          * Activates the context for use.
77          */
78         void activate();
79 
80         /**
81          * Destroys a context.
82          */
83         void destroy();
84 
85         /**
86          * Swap the buffers, to make the output display.
87          */
88         void swapBuffers();
89 
90         /**
91          * What type of context is this?
92          * 
93          * Returns:
94          * 		The context type.
95          */
96         WindowContextType type();
97 
98         /**
99          * Version of the toolkit being used.
100          * 
101          * Returns:
102          * 		The toolkit version.
103          * 		This is implementation defined with no clear structure.
104          * 		Is for debugging/logging and should not be relied upon.
105          */
106         string toolkitVersion();
107 
108         /**
109          * Version of the shading language available
110          * 
111          * Returns:
112          * 		The shader language version.
113          * 		This is implementation defined with no clear structure.
114          * 		IS for debugging/logging and should not be relied upon.
115          */
116         string shadingLanguageVersion();
117     }
118 }
119 
120 /**
121  * Allows for drawing into a predefined buffer for 2d operations
122  */
123 interface ContextBuffer2D : IContext {
124 	@property {
125 		/**
126 		 * Buffer to draw into.
127 		 * Default value will be null. Must be set first before using.
128 		 * 
129 		 * Returns:
130 		 * 		The buffer that can be drawn into.
131 		 * 		Will not clear between swapping of buffers.
132 		 */
133 		ref Image buffer();
134 
135 		/**
136 		 * Sets the buffer to draw into.
137 		 * 
138 		 * Params:
139 		 * 		buffer	=	The image buffer to draw into
140 		 */
141 		void buffer(Image buffer);
142 	}
143 }